<template>
  <div>
    <el-button @click="dialogVisible = true">显示dialog</el-button>
    <el-dialog title="这是标题" :visible.sync="dialogVisible">
      <el-form ref="form" label-width="80px" :model="formData">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="formData.name"></el-input>
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="formData.age"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer">
        <el-button @click="cancel">取消</el-button>
        <el-button @click="confirm" type="primary">确定</el-button>
      </span>
    </el-dialog>

    <!-- 分页条 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 30, 100]"
      :page-size="pageSize"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="400"
    >
    </el-pagination>
    {{ pageIndex }}
    {{ pageSize }}
  </div>
</template>

<script>
export default {
  data() {
    return {
      dialogVisible: false,
      formData: {
        name: "",
        age: "",
      },
      pageIndex: 1,
      pageSize: 10,
    };
  },
  methods: {
    //   切换页码触发的方法
    handleCurrentChange(value) {
      console.log("当前页码", value);
      this.pageIndex = value;
    },
    //分页的条数变动时触发的方法
    handleSizeChange(value) {
      console.log("当前每页" + value + "条");
      this.pageSize = value;
    },
    cancel() {
      this.$refs.form.resetFields();
      this.dialogVisible = false;
    },
    confirm() {
      this.$refs.form.resetFields();
      this.dialogVisible = false;
    },
  },
};
</script>